<?php require_once 'header.php';?>

	<div id = "pagecontent">
		<h1>Shopping Cart</h1>
		
		<p>
		<?php 
			$removed = 0;
			$totalPrice = 0;
			$items = $cart->returnCart();
			$index = $cart->returnIndex();
			$amounts = $cart->returnCartAmounts();
			for($i=0; $i<$index; $i++)
			{
				echo "<form action='shoppingCart.php' method='post'>";
				for($j=0; $j<$index; $j++)
				{
				if(isset($_POST['removed']))
				{
					
					$id = $_POST['removed'];
					if($id == $items[$j] && $removed == 0)
					{
						$removed++;
						//echo "REMOVING: $items[$j]";
						$cart->removeItemFromCart($items[$j]);
						$items = $cart->returnCart();
						$index = $cart->returnIndex();
						$amounts = $cart->returnCartAmounts();
						echo "<script language='JavaScript'>window.location.href='shoppingCart.php'</script>";
					}
				}
					
				}
				
				
				$query = "SELECT * FROM item WHERE no = '$items[$i]'";
				$result = $DTB->query($query);
				$name = mysql_result($result,0,'name');
				$itemPrice = mysql_result($result,0,'price');
				$allPrice = $itemPrice * $amounts[$i];
				$totalPrice += $allPrice;
				echo "$name X $amounts[$i] .....$$allPrice ";
				
				
				echo "<input type='hidden' name='removed' value='$items[$i]'/>";
				echo "<input type='submit' name='remove' value='Remove One'/></form>";
			}
			echo "<br>Total: $$totalPrice";
			
			echo "<form action='shoppingCart.php' method='post'>";
			
			if(isset ($_POST['checkout']))
			{
				$id = $_POST['checkout'];
				echo "$id";
				if($id == "Checkout")
				{
					echo "<script language='JavaScript'>window.location.href='payment.php'</script>";
				}	
			}
			if(isset ($_POST['back']))
			{
				$id = $_POST['back'];
				echo "$id";
				if($id == "back")
				{
					echo "<script language='JavaScript'>window.location.href='Menu.php'</script>";
				}	
			}
			echo "<br><br><input type='submit' name='checkout' value='Checkout'/>";
			echo "<input type='submit' name='back' value='back'/></form><br><br>";
			echo "</form>";
		?>
		</p>
	
	</div><!-- end of pagecontent -->

<?php require_once 'footer.php';?>